<?php
/**
 * Created by PhpStorm.
 * User: jsq
 * Date: 2017/12/1 0001
 * Time: 16:46
 */

namespace app\admin\logic;

use app\admin\model\AuthGroup;
use think\Cache;

class Role
{

    /**
     * 获取所有的状态（供获取器使用）
     * @return array|false|mixed|\PDOStatement|string|\think\Collection
     */
    public static function rolesToText(){
        $states = self::getAllRoles();
        $states = collect($states)->column('usersname','id');
        return $states;
    }

    /**
     * 获得所有的状态（从缓存中）
     * @return false|mixed|\PDOStatement|string|\think\Collection   返回数组
     */
    public function getAllRoles(){
        if (!empty(Cache::get('allRoles'))){
            return Cache::get('allRoles');
        }else{
            $states = AuthGroup::all();
            Cache::set('allRoles',$states);
            return $states;
        }
    }

    /**
     * 获取启用的状态
     * @return array|false|mixed|\PDOStatement|string|\think\Collection
     */
    public function getEnabledRoles(){
        $states = $this->getAllRoles();
        $states = collect($states)->where('status',1)->all();
        $states = collection($states)->toArray();
        $states = array_merge($states);
        return $states;
    }



}